<template>
    <h2>{{username}}</h2>
    <button @click="reset">点击重置</button>
    <ul>
        <li v-for="item in data" :key="item.id">{{item.title}}</li>
    </ul>
</template>  

<script setup>
    import {useUser} from "../store/users"
    import {storeToRefs} from "pinia"
 
    let useStore = useUser()

    let {username,data} = storeToRefs(useStore);
    console.log(username);

    setTimeout(()=>{
        // useStore.username = "bbb"
        username.value = "zzz"

        
    },2000)

    console.log(useStore.username);

    let reset = ()=>{
        useStore.$reset()
    }

    useStore.$subscribe((mutation,state)=>{
        console.log(state);
        console.log(mutation);
    })

    useStore.fetch_data(1,2)
</script>